<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/11/10 0010
 * Time: 17:33
 */

namespace app\api\controller\v1;


use think\Controller;
use app\common\model\Banner as BannerModel;
use app\common\model\Goods as GoodsModel;
use app\common\model\Brand as BrandModel;

class Index extends Controller
{
    /**
     * 首页数据
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function index() {
        // 获取banner
        $banner = BannerModel::getList();

        // 首页推荐商品
        $newest = GoodsModel::getRecommendList();

        // 首页热销
        $best = GoodsModel::getHot();

        // 推荐品牌
        $brand =BrandModel::getRecommendList();

        return return_data('首页信息', 0, [
            'items' => [
                [
                    'type' => 'search',
                ],
                [
                    'type' => 'banner',
                    'data' => $banner
                ]
            ],
            'newest' => $newest,
            'best' => $best,
            'brand' => $brand
        ]);
    }
}